package com.ali.common;

import lombok.Data;

@Data
public class Response<T> {
    private String code;
    private String message;
    private T data;
    private long timestamp;

    Response() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.setCode(ReturnEnum.RC200.getCode());
        response.setMessage(ReturnEnum.RC200.getMessage());
        response.setData(data);
        return response;
    }

    public static <T> Response<T> fail(String code, String message) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

    public static <T> Response<T> fail(String code, String message, T data) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(message);
        response.setData(data);
        return response;
    }
}